package com.yanu.trace.t2s.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yanu.trace.t2s.entity.Pig;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yanu.trace.t2s.entity.Pork;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author whj
 * @since 2021-06-23
 */
public interface PigMapper extends BaseMapper<Pig> {
    /**
     * 根据eid查询一个企业所有的猪并分页返回
     * @param page
     * @param eid
     * @return
     */
    @Select("select * from pig  where enter_id = #{eid} ")
    IPage<Pig> selectPageVoByeid(Page<?> page,Integer eid);
    @Select("select * from pig")
    IPage<Pig> selectPageVoAll(Page<?> page);

    /**
     * 联立pig和enterprise表 并根据猪的id查询指定的猪信息
     * @param id
     * @return
     */
    @Select("select p.*,e.* from pig p,enterprise e where p.enter_id = e.id and #{id} =p.id ")
    @Results(id = "peMap", value = {
            @Result(column = "id",property = "id"),
            @Result(column = "breed_place",property = "breed_place"),
            @Result(column = "weight",property = "weight"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "traits",property = "traits"),
            @Result(column = "check_status",property = "check_status"),
            @Result(column = "check_id",property = "check_id"),
            @Result(column = "out_date",property = "out_date"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "enter_id",property = "enter_id"),
            @Result(column = "cut_state",property = "cut_state"),
            @Result(column = "enter_id", property = "enterprise", one = @One(select = "com.yanu.trace.t2s.mapper.EnterpriseMapper.selectById"))
    })
    Pig selectByidpae(Integer id);

}
